@extends('fontend.master')

@section('content')
	@if (Session::has('mess'))
		<div class="alert alert-success" role="alert">{{Session::get('mess')}}</div>
	@endif
	<h2>{{$title}}</h2>

	{{Form::open(array('route'=>'update_cart'))}}
		<table class="table table-bordered table-striped table-hover">
			<tr class="info">
				<td>ID</td>
				<td>Title</td>
				<td>Price</td>
				<td>Images</td>
				<td>Number</td>
				<td>Money</td>
				<td>Action</td>
			</tr>
			<?php $sum = ""; ?>
			@if(isset($cart))
				@foreach ($cart as $k=>$item)
					<tr>
						<td>{{$k}}</td>
						<td>{{$item['name']}}</td>
						<td>{{Currency::format($item['price'],'VND','')}}</td>
						<td><img src="{{$item['img']}}" style="width:100px;height:100px"></td>
						<td>
							{{Form::text("num[$k]",$item['num'],array('size'=>3))}}

						</td>
						<td>{{Currency::format($item['price'] * $item['num'],'VND','')}}</td>
						<?php $sum += $item['price'] * $item['num'] ?>
						<td><a href="{{URL::route('deleteitem_cart',array($k))}}" class="btn btn-danger">Remove</a></td>
					</tr>
				@endforeach
				<tr>
					<td colspan="5">Total:</td>
					<td>{{Currency::format($sum,'VND','')}}</td>
					<td><a href="{{URL::route('deleteall_cart')}}" class="btn btn-danger">Remove all</a></td>
				</tr>
				<tr>
					<td colspan="7" align="center">
						<button href="{{URL::route('update_cart')}}" class="btn btn-warning">Update cart</button>
						<a href="{{URL::route('indexhome')}}" class="btn btn-info">Mua tiếp</a>
						<script language="javascript">
							function showForm(idform){
								$idform = $("#"+idform);
								if($idform.is(":hidden")){
									$idform.fadeIn("fast");
								}else{
									$idform.fadeOut("fast");
								}
							}
						</script>
						<a href="javascript:void(0)" class="btn btn-success" onClick="showForm('add_cart')">Checkout</a>
					</td>
				</tr>
				
			@else
				<tr>
					<td colspan="6" align="center">No item - <a href="{{URL::route('indexhome')}}">Thêm sản phẩm vào giỏ hàng</a></td>
				</tr>
			@endif
		</table>

	{{Form::close()}}

	
	{{Form::open(array('route'=>'checkout_cart','id'=>'add_cart','style'=>'display:none'))}}
		<p class="minihead">Tên người dùng:</p>

		{{Form::text('username',Input::old('username'),array('class'=>'form-control'))}}

		<p class="minihead">Email:</p>

		{{Form::email('email',Input::old('email'),array('class'=>'form-control'))}}

		<p class="minihead">Địa chỉ:</p>

		{{Form::textarea('address',Input::old('address'),array('class'=>'form-control'))}}

		<p class="minihead">Số điện thoại:</p>

		{{Form::text('phone',Input::old('phone'),array('class'=>'form-control'))}}<br>

		{{Form::submit('Gửi',array('class'=>'btn btn-primary btn-lg'))}}
	{{Form::close()}}
	
@endsection

@section('data_code')
	
@endsection